Fix a flaky test in ApproximateQuantilesTest#39132
Conversation
|
r: @derrickaw |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses flakiness in the Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a deterministic tie-breaker helper method, _sum_and_second, to prevent flaky test failures in test_batched_quantiles when using key=sum. The feedback suggests optimizing this helper function by replacing sum(x) with x[0] + x[1] to avoid the overhead of iterating over the 2-tuple.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #39132 +/- ##
============================================
+ Coverage 58.62% 58.67% +0.05%
Complexity 15246 15246
============================================
Files 2769 2770 +1
Lines 275617 276049 +432
Branches 12163 12163
============================================
+ Hits 161577 161976 +399
- Misses 107621 107654 +33
Partials 6419 6419
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks! |
In
test_batched_quantiles, when configuringApproximateQuantiles.Globallywithkey=sum, multiple input tuples (specifically (72.5, 225) and (22.5, 275)) evaluate to the exact same key value (297.5).Because sum is used as the sole comparison key, the ordering between elements with identical sums is non-deterministic and sensitive to bundle execution/merging order as well as shared class-level jitter state. This leads to flaky test assertions when asserting the exact elements in the computed quantiles.
Failed test example:
https://github.com/apache/beam/actions/runs/28270530208/job/83766814632?pr=39130
Traceback:
In this PR, we introduced a secondary sorting key via a static helper method _sum_and_second(x). This ensures that if the sums of two elements are identical, they are compared using their second element, making the comparison completely deterministic.